/**
 * Created by MonSterist on 2017/12/8.
 */
angular.module('modelapp', [
    'ui.bootstrap',
    'ui.router',
    'module.auth',
    'ngFileUpload',
    'module.test',
    'module.mainpage',
    'module.knowledge',
    'module.personalcenter',
    'module.collect',
    'service.fileupload',
    'service.mainpage',
    'service.knowledge',
    'service.auther',
    'service.personalcenter'
])

.run(
    ['$rootScope', '$state', '$stateParams','$cookies',
        function ($rootScope, $state, $stateParams,$cookies) {
            $rootScope.$state = $state;
            $rootScope.$stateParams = $stateParams;
            $rootScope.$on('$stateChangeStart',function(event, toState, toParams, fromState){
                //需要验证登录的state
                var checkState=["addplant","collect","personalcenter"];
                console.log("toState=",toState);
                //console.log("checkState=",checkState);
                for(var i=0;i<checkState.length;i++){
                    if(angular.equals(toState.name,checkState[i])){
                        //console.log($cookies.get("userInfo"));
                        if(!$cookies.get("userInfo")){
                            //$state.transitionTo("login", null, {notify:false});
                            $state.go("login");
                            //window.location.href = "#/login"
                        }
                    }
                }
                $(window).scrollTop(0);
            })
        }
    ]
)
.config(
    ['$stateProvider', '$urlRouterProvider', '$locationProvider', '$httpProvider',
        function ($stateProvider, $urlRouterProvider, $locationProvider, $httpProvider) {
            $httpProvider.defaults.withCredentials = true;
            $urlRouterProvider
                // .otherwise('/login');
                //.otherwise('/test');
                 .otherwise('/mainpage');
                // .otherwise('/knowledge');
                //.otherwise('/personalcenter');
                //.otherwise('/login');
        }
    ]
);